package cn.tedu.sp09.controller;
import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp09.service.ItemFeignClient;
import cn.tedu.sp09.service.OrderFeignClient;
import cn.tedu.sp09.service.UserFeignClient;
import cn.tedu.web.util.JsonResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
public class FeignController {

    @Resource
    private ItemFeignClient itemFeignClient;
    @Resource
    private UserFeignClient userFeignClient;
    @Resource
    private OrderFeignClient orderFeignClient;
    @GetMapping("/item-client/{orderId}")
    public JsonResult<List<Item>> getItems(@PathVariable String orderId){
        return itemFeignClient.getItems(orderId);
    }
    @PostMapping("/item-service/decreaseNumber")
    public JsonResult decreaseNumber(@RequestBody List<Item> items) {
        return itemFeignClient.decreaseNumber(items);
    }
    @GetMapping("/user-service/{userId}")
    public JsonResult<User> getUser(@PathVariable Integer userId) {
        return userFeignClient.getUser(userId);
    }
    @GetMapping("/user-service/{userId}/score")
    public JsonResult addScore(@PathVariable Integer userId, Integer score) {
        return userFeignClient.addScore(userId, score);
    }
    @GetMapping("/order-service/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId) {
        return orderFeignClient.getOrder(orderId);
    }
    @GetMapping("/order-service")
    public JsonResult addOrder() {
        return orderFeignClient.addOrder();
    }
}
